#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>





int main()
{

	int sock = 0;
	int listenfd = 0;
	int ret = 0;


	struct sockaddr_in addr;
    memset(&addr,0,sizeof(addr));

	sock = socket(AF_INET,SOCK_STREAM,0);
	if(sock == -1)
	{
		perror("sock");
		exit(-1);
	}

	addr.sin_family = AF_INET;
    addr.sin_port = htons(6868);
    addr.sin_addr.s_addr = inet_addr("192.168.0.181");

	ret = bind(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr));
	if(ret == -1)
	{
		perror("bind");
		exit(-1);
	}


	listen(sock,5);

	listenfd = accept(sock,NULL,NULL);
	if(listenfd == -1)
	{
		perror("accpet");
		exit(-1);
	}

	char buf1[1024] = {0};

 while(1)
 {
	ret = recv(listenfd,buf1,1023,0);
	if(ret == -1)
	{
		perror("recv");
		exit(-1);
	}

	printf("buf is %s\n",buf1);
	ret = send(listenfd,buf1,strlen(buf1),0);
	if(ret == -1)
	{
		perror("send");
		exit(-1);
	}
 }


	close(listenfd);
	close(sock);

}



